<template>
  <div class="card_child">
    <div class="img_warp">
      <img v-if="props.data.coverImg" :src="props.data.coverImg" alt="loading">
    </div>
    <div class="header_wrap">
      <p class="title ellipsis hover:text-[var(--devui-brand)]">
        {{ props.data.title }}
      </p>
      <p class="desc ellipsis">
        {{ props.data.desc }}
      </p>
      <div class="count_wrap">
        <div class="time">
          <span>{{ dayjs(new Date(props.data.releaseTime).getTime()).format('YYYY-MM-DD') }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang='ts' setup>
import dayjs from 'dayjs'
import type { IResult } from '../types/index'


defineOptions({ name: 'Card' })
const props = withDefaults(defineProps<{
  data: IResult
}>(), {
  data() {
    return {
      releaseTime: '',
      id: '',
      path: '',
      title: '',
      desc: '',
      coverImg: ''
    }
  },
})
</script>

<style scoped lang='scss'>
.card_child {
  cursor: pointer;
  box-shadow: 0 1px 3px 0 #1D1F3A05, 0 2px 6px 0 #1D1F3A05, 0 4px 12px 0 #1D1F3A05, 0 8px 24px 0 #1D1F3A0A;
  border-radius: 8px;
  transition: all .3s linear;
  &:hover {
    transform: translateY(-10px);
  }
 
  .header_wrap {
    padding: 16px;
  }

  .title {
    font-size: 14px;
    font-weight: 900;
  }

  .desc {
    font-size: 12px;
    color: #9C9DB4;
    line-height: 20px;
    padding: 8px 0;
  }

  .ellipsis {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .count_wrap {
    display: flex;
    align-items: center;

    .star_count_wrap {
      font-size: 12px;
      color: #9C9DB4;
    }

    .time {
      span {
        font-size: 12px;
        color: #9C9DB4;
      }
    }
  }

  .img_warp {
    height: 120px;
    overflow: hidden;
    img {
      object-fit: cover;
      width: 100%;
      height: 100%; 
      border-top-left-radius: 8px;
      border-top-right-radius: 8px;
    }
  }
}


@media screen and (max-width: 768px) {
  .card_child {
    .count_wrap {
      display: none;
    }
    .header_wrap {
      padding: 8px;
    }
    .desc {
      padding-bottom: 0;
    }

    .img_warp {
      overflow: hidden;
      height: 70px;
      img {
        object-fit: cover;
        width: 100%;
        height: 100%;
      }
    }
  }

}
</style>
